package cn.com.yusys.yusp.admin.web.rest;

import cn.com.yusys.yusp.admin.domain.AdminSmUserMgrOrg;
import cn.com.yusys.yusp.admin.service.AdminSmUserMgrOrgService;
import cn.com.yusys.yusp.commons.mapper.QueryModel;
import cn.com.yusys.yusp.commons.service.CommonService;
import cn.com.yusys.yusp.commons.util.DateUtil;
import cn.com.yusys.yusp.commons.web.rest.CommonResource;
import cn.com.yusys.yusp.commons.web.rest.dto.ResultDto;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 
 * @项目名称: yusp-admin
 * @类名称: AdminSmUserMgrOrgResource
 * @类描述: 用户授权管理resource
 * @功能描述: 
 * @创建人: hujun3@yusys.com.cn
 * @创建时间: 2017-12-27 11:26
 * @修改备注: 
 * @修改记录: 修改时间    修改人员    修改原因
 * -------------------------------------------------------------
 * @version 1.0.0
 * @Copyright (c) 2017宇信科技-版权所有
 */
@RestController
@RequestMapping("api/adminsmusermgrorg")
public class AdminSmUserMgrOrgResource extends CommonResource<AdminSmUserMgrOrg, String> {

	private Logger logger = LoggerFactory.getLogger(AdminSmUserMgrOrgResource.class);
	@Autowired
	private AdminSmUserMgrOrgService service;
	@Override
	protected CommonService getCommonService() {
		return this.service;
	}
	/**
	 * 
	* @方法名称: getList
	* @方法描述: 分页查询
	* @参数与返回说明: 
	* @算法描述:
	 */
	@GetMapping("/querypage")
	public ResultDto<List<Map<String, Object>>> getList(QueryModel queryModel) {
		List<Map<String, Object>> list = service.queryPage(queryModel);
		return new ResultDto<List<Map<String, Object>>>(list);
	}
	
	/**
	 * 
	* @方法名称: addUserMgrOrg
	* @方法描述: 新增用户授权机构
	* @参数与返回说明: 
	* @算法描述:
	 */
	@PostMapping("/addusermgrorg")
	public ResultDto<Object> addUserMgrOrg(@RequestBody AdminSmUserMgrOrg pool) {
		Map<String, Object> list = service.insertInfo(pool);
		return new ResultDto<Object>(list);
	}
	
	/**
	 * 
	* @方法名称: useBatch
	* @方法描述:  批量启用
	* @参数与返回说明: ids 数据ID主键
	* @算法描述:
	 */
	@PostMapping("/usebatch")
	public ResultDto<Object> useBatch(@RequestBody Map<?, ?> ids) {
		int n=0;
		if(ids !=null&&!"".equals(ids.toString())) {
			String[] idStr=ids.get("id").toString().split(",");
			for(int i=0;i<idStr.length;i++) {
				if(!"".equals(idStr[i])) {
					n=n+this.service.updateSts("A",idStr[i]);
				}
			}
			logger.info("Batch enable organizations [PK:{"+ids+"}] "+ DateUtil.formatDateTimeByDef());
		}
		return new ResultDto<Object>(n);
	}
	
	/**
	 * 
	* @方法名称: unUseBatch
	* @方法描述:批量停用 
	* @参数与返回说明: ids 数据ID主键
	* @算法描述:
	 */
	@PostMapping("/unusebatch")
	public ResultDto<Object> unUseBatch(@RequestBody Map<?, ?> ids) {
		int n=0;
		if(ids !=null&&!"".equals(ids.toString())) {
			String[] idStr=ids.get("id").toString().split(",");
			for(int i=0;i<idStr.length;i++) {
				if(!"".equals(idStr[i])) {
					n=n+this.service.updateSts("I", idStr[i]);
				}
			}
			logger.info("Batch enable user authorized organization [PK:{"+ids+"}] "+ DateUtil.formatDateTimeByDef());
		}
		return new ResultDto<Object>(n);
	}
	
	/**
	 * 
	* @方法名称: deleteBatch
	* @方法描述: 批量删除
	* @参数与返回说明: ids 数据ID主键
	* @算法描述:
	 */
	@PostMapping("/deletebatch")
	public ResultDto<Object> deleteBatch(@RequestBody Map<?, ?> ids) {
		int n=0;
		if(ids !=null&&!"".equals(ids.toString())) {
			String[] idStr=ids.get("id").toString().split(",");
			for(int i=0;i<idStr.length;i++) {
				if(!"".equals(idStr[i])) {
					n=n+this.service.deleteByPrimaryKey(idStr[i]);
				}
			}
			logger.info("Batch delete user authorized organization [PK:{"+ids+"}] "+ DateUtil.formatDateTimeByDef());
		}
		return new ResultDto<Object>(n);
	}
}
